/*
 * RoleTestPanel.cpp
 *
 *  Created on: 2012-11-3
 *      Author: tutu
 */

#include "RoleTestPanel.h"
#include "../TContext.h"
#include <QMessageBox>

RoleTestPanel::RoleTestPanel(QWidget *parent) : QWidget(parent)
{
	_listButton = new QPushButton(this);
	_listButton->setText("List All");
	_listButton->setGeometry(10, 10, 100, 30);
	connect(_listButton, SIGNAL(clicked()), this, SLOT(listButtonClicked()));

	_requester = TContext::instance()->requesterFactory()->createRoleRequester();
	connect(_requester.data(), SIGNAL(requestFinished(bool, QList<TRolePointer>)), this, SLOT(requestFinished(bool, QList<TRolePointer>)));
}

RoleTestPanel::~RoleTestPanel()
{
	// TODO Auto-generated destructor stub
}

void RoleTestPanel::listButtonClicked()
{
	_requester->requestAllRoles();
}

void RoleTestPanel::requestFinished(bool error, QList<TRolePointer> roles)
{
	if(!error)
	{
		QMessageBox::warning(NULL, "Result", "List Success. Role number is "+QString::number(roles.size()));
	}
	else
	{
		QMessageBox::warning(NULL, "Result", "List Failure.");
	}
}
